package com.wrk._2_数组._02_习题;

public class _012_验证杨辉三角行 {
    public static void main(String[] args) {
        //定义不规则数组，初始化行，列可省略
        int [][] yangHuiTriangle = new int[8][];
        //验证杨辉三角形
        for (int i = 0; i < yangHuiTriangle.length; i++) {
            //初始化不规则数组的列
            yangHuiTriangle[i] = new int[i+1];
            //前两行赋值
            if (i <= 1){
                for (int a =0 ; a<= i; a++){
                    yangHuiTriangle[i][a] = 1;
                }
            }
            //输出后续几行
            if (i >1){
                for (int b = 0; b <= i ; b++){
                    //首列赋值
                    if (b == 0){
                        yangHuiTriangle[i][b] = 1;
                    }
                    //中间赋值
                    if (b > 0 && b < yangHuiTriangle[i].length -1){
                        yangHuiTriangle[i][b] = yangHuiTriangle[i-1][b -1] + yangHuiTriangle[i-1][b];
                    }
                    //末尾赋值
                    if (b == yangHuiTriangle[i].length -1 ){
                        yangHuiTriangle[i][yangHuiTriangle[i].length - 1] = 1;
                    }
                }
            }
        }
        //打印数组
        for (int i = 0; i < yangHuiTriangle.length; i++) {
            //打印空格
            for (int d = yangHuiTriangle.length - i -1 ;d > 0;d--){
                System.out.print("  ");
            }
            for (int j = 0; j < yangHuiTriangle[i].length; j++) {
                System.out.print(yangHuiTriangle[i][j]+"  ");
            }
            System.out.println();
        }
    }
}
